<template>
  <node
    :title="config.name"
    :show-error="showError"
    :content="content"
    :error-info="errorInfo"
    @selected="$emit('selected')"
    @delNode="$emit('delNode')"
    @insertNode2="type => $emit('insertNode', type)"
    placeholder="请设置抄送人"
    header-bgc="#3296fa"
    header-icon="el-icon-s-promotion"
  />
</template>

<script setup name="CcNode" lang="ts">

const props = defineProps({
  config: {
    type: Object,
    default: () => {
      return {};
    }
  }
})
const config =ref(props.config)

const showError=ref(false)

const errorInfo=ref('')

const content =computed(()=>{
  if (config.value.props.assignedUser.length > 0) {
    let texts: any[] = []
    config.value.props.assignedUser.forEach((org: { name: any; }) => texts.push(org.name))
    return String(texts).replaceAll(',', '、')
  } else {
    return null
  }
})

const validate = () => {
  showError.value = false
  if(config.value.assignedUser && config.value.assignedUser.length > 0){
    showError.value = false
  }else {
    showError.value = true
    errorInfo.value = '请选择需要抄送的人员'
  }
  return !showError.value
}
// 导出方法
defineExpose({validate})
</script>

<style scoped></style>
